﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DiveManager
{
    public partial class Rental_ArtikelView : Form
    {
        public string id_weitergabe;

        protected DiveDatabaseEntities diveDatabase;
        protected BindingSource bindingSource;
        
        public Rental_ArtikelView()
        {
            InitializeComponent();

            // Init Database
            diveDatabase = new DiveDatabaseEntities();
            bindingSource = new BindingSource();
        }

        public string Weitergabe_Details
        {
            get;
            set;
        }

        protected void LoadData()
        {
            Guid id_guid = new Guid(id_weitergabe);
            IQueryable<Rental_Artikel_table> dataQuery = (from rat in diveDatabase.Rental_Artikel_table
                                                          where rat.Group == id_guid  
                                                          select rat);

            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;

            // Bind BindingSource to List
            ArtikelList.DataSource = bindingSource;


            // Hide ID-Columns
            ArtikelList.Columns["ID"].Visible = false;
            ArtikelList.Columns["Group"].Visible = false;
            ArtikelList.Columns["Artikel"].Visible = true;
            ArtikelList.Columns["Beschreibung"].Visible = true;
            ArtikelList.Columns["Preis_Club"].Visible = false;
            ArtikelList.Columns["DSD_Sort"].Visible = false;


            // Set Column Headers
            ArtikelList.Columns["Artikel"].HeaderText = "Artikel";
            ArtikelList.Columns["Beschreibung"].HeaderText = "Beschreibung";

        }

        private void Rental_ArtikelView_Load(object sender, EventArgs e)
        {
            this.id_weitergabe = Weitergabe_Details;
            label1.Text = id_weitergabe;

            Guid id_guid = new Guid(id_weitergabe);
            
            var query = from rg in diveDatabase.Rental_Group
                        where rg.ID == id_guid
                        select rg;

            foreach (var rg in query)
            {
                txGroupName.Text = rg.Name;
            }

            LoadData();
        }
    }
}
